import numpy as np

# generate matrix
a = np.arange(15).reshape(3, 5)
print(a)
print(a.shape)  # 3,5

# the number of axes (dimensions) of the array
print(a.ndim)

# dtype
print(a.dtype)

# generate matrix all elements are zeros
# zeros = np.zeros(3, 4) this pattern is wrong!
zeros = np.zeros((3, 4), dtype=np.int32)
print(zeros)

ones = np.ones((2, 3, 4), dtype=np.int32)
print(ones)

# generate array [10 15 20 25]
a = np.arange(10, 30, 5)
print(a)
# 0~2 step=0.3
a = np.arange(0, 2, 0.3)
print(a)

# generate random array
# [[ 0.17076987  0.50484461  0.40632787]
# [ 0.52614606  0.74996835  0.83161203]]
a = np.random.random((2, 3))
print(a)

from numpy import pi

# 0-2pi generate 100 points
a = np.linspace(0, 2 * pi, 100)
print(a)

# calculate sin
a = np.sin(np.linspace(0, 2 * pi, 100, dtype=np.float))
print(a)

a = np.array([20, 30, 40, 50])
b = np.arange(4)

# each elements in A and B , operates
c = a - b
print(c)

# square
print(b ** 2)

# cubic
print(b ** 3)

A = np.array([[1, 1],
              [0, 1]])
B = np.array([[2, 0],
              [3, 4]])

# each element in A multiply with another in B, which has the same index
# [2 0 0 4]
print(A*B)

# matrix multiply
print(A.dot(B))
# this two patterns are the same
print(np.dot(A, B))
